# -*- coding: utf-8 -*-
# @Time    : 2020/12/20 下午9:39
# @Author  : lilong

import torch.nn as nn
import torch
import math


"""位置编码"""

# max_len = 512
# d_model = 10
#
# pe = torch.zeros(max_len, d_model).float()
# pe.require_grad = False
#
# position = torch.arange(0, max_len).float().unsqueeze(1)
# div_term = (torch.arange(0, d_model, 2).float() * -(math.log(10000.0) / d_model)).exp()
#
# pe[:, 0::2] = torch.sin(position * div_term)
# pe[:, 1::2] = torch.cos(position * div_term)
#
# pe = pe.unsqueeze(0)
# print("pe:", pe.shape)


mm = torch.tensor(
    [[[0., 1., 2., 0],
    [3., 4., 5., 0],
    [6., 7., 8., 0],
    [9., 10., 11., 0]]])

print(mm[:, 0::1])
print(mm[:, 0:2:1])
print(mm[:, 0::2])
print(mm[:, 1::2])
print(mm[:, :2])

print(mm.size())
print(mm[:, :mm.size(1)])



